from django.contrib.auth.models import AbstractUser
from django.db import models

from sportsground.utils.baseModels import BaseModels, IntegerChoices


class Account(AbstractUser, BaseModels):
    """ 自定义账号模型类 """

    class Meta:
        db_table = 'account'
        verbose_name = '账号'
        verbose_name_plural = verbose_name

    class Roles(IntegerChoices):
        User = 1, "用户"
        Venue = 2, "馆场方"

    username = models.CharField(
        max_length=150,
        unique=False,
    )
    role = models.IntegerField(choices=Roles.choices, default=Roles.User, verbose_name="角色")

    user = models.ForeignKey(to="User.User", null=True, on_delete=models.CASCADE, verbose_name="对应用户")
    venue = models.ForeignKey(to="Venue.Venue", null=True, on_delete=models.CASCADE, verbose_name="对应馆场")

    def __str__(self):
        return self.username


"""
# 生成迁移文件
# 
# 执行迁移
python manage.py makemigrations
python manage.py migrate
"""
